import 'dart:convert';

import '../entity/user_entity.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SpUtilForUser{
  SharedPreferences _preferences;

  void pushUser(UserEntity user) async{
    _preferences = await SharedPreferences.getInstance();
    _preferences.clear();
    _preferences.setString("user", jsonEncode(user).toString());
  }

  Future<UserData> getUser() async{
    _preferences = await SharedPreferences.getInstance();
    //print("getUser():"+_preferences.get("user"));
    var userJson = _preferences.get("user");
    Map userDataMap = json.decode(userJson);
    //print("getUser()"+userDataMap.toString());
    UserData userData = UserEntity().fromJson(userDataMap).data;
    //print("getUser()"+userData.toString());
    return userData;
  }
}